﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Pheonix.Fashionzoomer.BLL;
using Pheonix.CodeLibrary;
using System.Text;
using System.Collections.Generic;
using Pheonix.CodeLibrary.Web;

public partial class page_private_user_messagebox : PrivateBasePage
{
   

    private void LoadMessageGrid()
    {
        DataTable dtMessageByUser = MessageManager.GetMessageOfReceiver(SessionManager.LoggedUser.Id);
        GVMessageBox.DataSource = dtMessageByUser;
        GVMessageBox.DataBind();

    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Title = SiteName + " - MessageBox";
        if (!Page.IsPostBack)
        {

            //CurrentUser currentUser=null;
            //try
            //{
            //    currentUser = SessionManager.LoggedUser;
            //    if (currentUser == null)
            //    {
            //        Response.Redirect("~/page/public/logon.aspx");
            //    }

            //}
            //catch (Exception ex)
            //{
            //    Response.Redirect("~/page/public/logon.aspx");
            //}           
            LoadMessageGrid();

        }
    }
    protected void BtnDelete_Click(object sender, EventArgs e)
    {
        List<int> DeleteMessageIdList=new List<int>();
        for (int i = 0; i < GVMessageBox.Rows.Count; i++)
        {
            GridViewRow row = GVMessageBox.Rows[i];
            CheckBox chkBox=((CheckBox)row.FindControl("chkSelect"));
            if (chkBox.Checked)
            {
                DeleteMessageIdList.Add(Int32.Parse(GVMessageBox.DataKeys[i].Value.ToString()));
            }
        }

        MessageManager.DeleteMessages(DeleteMessageIdList);

        LoadMessageGrid();
      
    }
    protected void GVMessageBox_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        try
        {
            HiddenField hfIsRead = (HiddenField)e.Row.FindControl("isRead");
            bool isRead = Boolean.Parse(hfIsRead.Value);
            Image imgMailBox = (Image)e.Row.FindControl("imgMailBox");
            
            if (isRead)
            {
                imgMailBox.CssClass = "readmail";            
            }
            else
            {
                imgMailBox.CssClass = "newmail";
                e.Row.Style["font-weight"] = "bold";
            }

        }
        catch { }

    }
    public string GetTextToPreview(object messageObj)
    {
        return Utility.ShortenText(messageObj.ToString(),200);
    }

    public string SetMessageLink(object messageObj, object messageIdLink,object senderEmail)
    {

        SiteConfigSection config = SiteConfigSection.SiteConfiguration;
        //string EncMsgId = Utility.Encrypt(messageIdLink.ToString(), config.SecurityKey, true);
        //string EncSendEmail = Utility.Encrypt(senderEmail.ToString(), config.SecurityKey, true);
        string EncMsgId = messageIdLink.ToString();
        string EncSendEmail =senderEmail.ToString();

       // return "<a onmousemove=\"TagToTip('termTooltip')\" onmouseout=\"UnTip()\" href='ReadReplyMessagePage.aspx?senderemail=" + EncSendEmail + "&messangeid=" + EncMsgId + "'>" + Utility.ShortenText(messageObj.ToString(), 50) + " </a>";
        return "<a onmouseover=\"TagToTip('hdTip" + messageIdLink.ToString() + "',FONTSIZE, '9pt', HEIGHT, 90, WIDTH, 240, TITLE, 'Message Preview', CLOSEBTN, true, STICKY, true, BGCOLOR, 'lightYellow',FADEOUT, 1000)\"  href='ReadReplyMessagePage.aspx?senderemail=" + EncSendEmail + "&messangeid=" + EncMsgId + "'>" + Utility.ShortenText(messageObj.ToString(), 50) + " </a>";
        //"Tip('id', FONTSIZE, '12pt', HEIGHT, 90, WIDTH, 240, TITLE, 'Limited Height', CLOSEBTN, true, STICKY, true);"
      
    }
}
